package com.tou.service;

import com.tou.model.BusinessUser;
import com.tou.repository.BusinessUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
public class BusinessUserService {

    @Autowired
    private BusinessUserRepository businessUserRepository;

    @Transactional
    public BusinessUser createBusinessUser(BusinessUser businessUser) {
        // 检查邮箱是否已经注册
        Optional<BusinessUser> existingBusinessUser = businessUserRepository.findByEmail(businessUser.getEmail());
        if (existingBusinessUser.isPresent()) {
            throw new RuntimeException("Business email is already in use");
        }

        // 保存企业用户
        return businessUserRepository.save(businessUser);
    }
}
